package com.ecnu.codelearn.common;

import java.io.Serializable;

/**
 * @author caopeisheng
 */
public class HttpResult<T> implements Serializable {
    private String code;
    private String message;
    private T data;

    private static final String SUCCESS_CODE = "00";
    private static final String FAIL_CODE = "01";

    public HttpResult() {
    }

    public HttpResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> HttpResult success(T data) {
        HttpResult httpResult = new HttpResult();
        httpResult.code = SUCCESS_CODE;
        httpResult.message = "success";
        httpResult.data = data;
        return httpResult;
    }

    public static HttpResult error(String errorMessage) {
        HttpResult httpResult = new HttpResult();
        httpResult.code = FAIL_CODE;
        httpResult.message = errorMessage;
        return httpResult;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
